package everydayGrade.t5;

/**
 * @Author: Siantar
 * @Date: 2024-07-14-22:26
 * @Description: 1.0
 */
public class T0807 {
    public int maxIncreaseKeepingSkyline(int[][] grid) {
        int n = grid.length;
        int[] rowMax = new int[n];
        int[] colMax = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                rowMax[i] = Math.max(rowMax[i], grid[i][j]);
                colMax[j] = Math.max(colMax[j], grid[i][j]);
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                    ans += Math.min(rowMax[i], colMax[j]) - grid[i][j];

        return ans;
    }
}
